package com.sky.controller.admin;


import com.aliyuncs.exceptions.ClientException;
import com.sky.result.Result;
import com.sky.utils.AliyunOOSUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@Slf4j
@RequestMapping("admin/common")
@Api(tags = "通用功能 文件上传")
public class CommonController {

    @Autowired
    AliyunOOSUtil aliyunOOSUtil;

    @PostMapping("/upload")
    @ApiOperation("图片上传")
    public Result<String> upload (MultipartFile file) throws IOException, ClientException {
        log.info("文件上传接收参数>: {}",file.getOriginalFilename());
        //获得带后缀的文件名
        String filename = file.getOriginalFilename();
        assert filename != null;
        String name = aliyunOOSUtil.upload(file.getBytes(), filename);

        return Result.success(name);
    };





}
